home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / prgtools / euphor13.zip / SB.EX < prev    next >
Text File  |  1994-09-23  |  2KB  |  83 lines

  1.         ------------------------------------
  2.         -- Atomic Reaction Screen Blanker --
  3.         ------------------------------------
  4. without type_check
  5.  
  6. include graphics.e
  7. include select.e
  8.  
  9. constant GRAPHICS_MODE = 18 -- VGA
  10.  
  11. constant POPULATION = 50                -- number of circles
  12. constant MAX_SIZE = 15, MIN_SIZE = 5    -- size of circles
  13.  
  14. constant TRUE = 1
  15. constant X = 1, Y = 2
  16. constant FILL = 1
  17.  
  18. sequence size, circles, dirs, colors
  19. sequence vc
  20.  
  21. procedure init()
  22. -- initialize global variables
  23.     if not select_mode(GRAPHICS_MODE) then
  24.     puts(1, "needs VGA graphics\n")
  25.     abort(1)
  26.     end if
  27.     vc = video_config()
  28.     circles = {}
  29.     dirs = {}
  30.     colors = {}
  31.     size = {}
  32. end procedure
  33.  
  34. procedure bounce()
  35. -- main routine
  36.     sequence top_left, prev_circle
  37.     integer x, y, s
  38.     atom t
  39.  
  40.     init()
  41.     t = time()
  42.     while t+2 > time() do
  43.     -- wait for screen to settle
  44.     end while
  45.     while TRUE do
  46.     if get_key() != -1 then
  47.         exit
  48.     end if
  49.     if length(circles) < POPULATION then
  50.         -- add a new circle
  51.         x = 0  y = 0 -- start each circle at top left corner of screen
  52.         s = MIN_SIZE + rand(MAX_SIZE+1-MIN_SIZE) - 1
  53.         size = append(size, s)
  54.         circles = append(circles, {{x, y}, {x, y}+s})
  55.         dirs = append(dirs, floor(s/2)+rand({10*s, 10*s})/10)
  56.         colors = append(colors, 8+rand(vc[VC_NCOLORS]/2-1))
  57.     end if
  58.  
  59.     -- move all the circles
  60.     for i = 1 to length(circles) do
  61.         top_left = circles[i][1]
  62.         prev_circle = circles[i]
  63.         if top_left[X] < 0 or top_left[X]+size[i] >= vc[VC_XPIXELS] then 
  64.         dirs[i][X] = -dirs[i][X] 
  65.         end if
  66.         if top_left[Y] < 0 or top_left[Y]+size[i] >= vc[VC_YPIXELS] then 
  67.         dirs[i][Y] = -dirs[i][Y] 
  68.         end if
  69.         top_left = top_left + dirs[i]
  70.         circles[i] = {top_left, top_left+size[i]}
  71.         -- blank out old position
  72.         ellipse(BLACK, FILL, prev_circle[1], prev_circle[2])
  73.         -- draw at new position
  74.         ellipse(colors[i], FILL, circles[i][1], circles[i][2])
  75.     end for
  76.     end while
  77.     if graphics_mode(-1) then
  78.     end if
  79. end procedure
  80.  
  81. bounce()
  82.  
  83.